package org.hongbo.springbootebsapi.service.login.impl;

import lombok.extern.slf4j.Slf4j;
import org.hongbo.springbootebsapi.entity.AuthUser;
import org.hongbo.springbootebsapi.service.login.ICurrentUser;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class CurrentUserImpl implements ICurrentUser {
    @Override
    public AuthUser getCurrentUser(){
        AuthUser userDetails =(AuthUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        return userDetails;
    }

    @Override
    public String getCurrentUserId(){
        return getCurrentUser().getUserId();
    }

    @Override
    public String getCurrentUserName(){
        return getCurrentUser().getUsername();
    }

    @Override
    public String getCurrentRespId(){
        return getCurrentUser().getRespId();
    }

    @Override
    public String getCurrentRespApplId(){
        return getCurrentUser().getRespApplId();
    }
}
